<template>
    <Card>
        <Row style="text-align: right;">
            <Button type="primary" icon="md-bookmark" @click="save" :loading="saveLoading"
                    v-show="parentParams.status!='view'">保存
            </Button>
            <Button type="primary" icon="md-backspace" @click="backPage">返回</Button>
        </Row>
        <br>
        <Form ref="voucherInfoFrom" :model="voucherInfoFrom" :rules="voucherInfoValidate"
              :label-width="200">
            <Alert>
                <h2>凭证信息</h2>
            </Alert>
            <Row>
                <Col span="10">
                    <FormItem label="主业务事件代码" prop="mainBusinessCode" :required=true>
                        <Poptip v-model="visible" placement="right-start" title="选择主业务事件代码">
                            <Input v-model="voucherInfoFrom.mainBusinessCode"
                                   :clearable="parentParams.status!='view'"
                                   readonly
                                   :disabled="parentParams.status=='view'"
                                   :style="{width:(item.width?item.width:100)+'%'}"/>
                            <div slot="content">
                                <Input v-model="searchMainKey" suffix="ios-search" @on-change="remoteMain"
                                       placeholder="输入主业务事件代码搜索"/>
                                <Scroll :on-reach-bottom="handleReachMainBottom">
                                    <Dropdown @on-click="scollListClick">
                                        <DropdownMenu>
                                            <DropdownItem :name="item.businessCode" v-for="item in options1">{{
                                                item.businessCode+":"+ item.business}}
                                            </DropdownItem>
                                        </DropdownMenu>
                                    </Dropdown>
                                </Scroll>
                            </div>
                        </Poptip>
                    </FormItem>
                </Col>
                <Col span="10" offset="4">
                    <FormItem label="主业务事件名称" prop="mainBusiness" :required=true>
                        <Input v-model="voucherInfoFrom.mainBusiness"
                               readonly
                               :disabled="parentParams.status=='view'"
                               :style="{width:(item.width?item.width:100)+'%'}"/>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="10">
                    <FormItem label="子业务事件代码" prop="childBusinessCode" :required=true>
                        <Poptip v-model="visibleChild" @on="remoteChild" placement="right-start" title="选择子业务事件代码">
                            <Input v-model="voucherInfoFrom.childBusinessCode"
                                   :clearable="parentParams.status!='view'"
                                   readonly
                                   :disabled="parentParams.status=='view'"
                                   :style="{width:(item.width?item.width:100)+'%'}"/>
                            <div slot="content">
                                <Input v-model="searchChildKey" suffix="ios-search" @on-change="remoteChild"
                                       placeholder="输入子业务事件代码搜索"/>
                                <Scroll :on-reach-bottom="handleReachChildBottom">
                                    <Dropdown @on-click="scollListChldClick">
                                        <DropdownMenu>
                                            <DropdownItem :name="item.businessCode" v-for="item in options2">{{
                                                item.businessCode+":"+ item.business}}
                                            </DropdownItem>
                                        </DropdownMenu>
                                    </Dropdown>
                                </Scroll>
                            </div>
                        </Poptip>
                    </FormItem>
                </Col>
                <Col span="10" offset="4">
                    <FormItem label="子业务事件名称" prop="childBusiness" :required=true>
                        <Input v-model="voucherInfoFrom.childBusiness"
                               readonly
                               :disabled="parentParams.status=='view'"
                               :style="{width:(item.width?item.width:100)+'%'}"/>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="10">
                    <Form-item label="数据来源" prop="dataSources" :required=false>
                        <Select placeholder="请选择" :style="{width:(item.width?item.width:100)+'%'}"
                                v-model="voucherInfoFrom.dataSources"
                                :clearable="parentParams.status!='view'" :disabled="parentParams.status=='view'">
                            <Option :key="item.value" :value="item.value" v-for="item in dataSources">{{ item.title }}
                            </Option>
                        </Select>
                    </Form-item>
                </Col>
                <Col span="10" offset="4">
                    <FormItem label="适用场景" prop="atomScope" :required=false>
                        <Select placeholder="请选择" :style="{width:(item.width?item.width:100)+'%'}"
                                v-model="voucherInfoFrom.atomScope" :clearable="parentParams.status!='view'"
                                :disabled="parentParams.status=='view'">
                            <Option :key="item.value" :value="item.value" v-for="item in voucherAtomScope">{{ item.title
                                }}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="24">
                    <FormItem label="描述" prop="description" :required=true>
                        <Input v-model="voucherInfoFrom.description" type="textarea"
                               :clearable="parentParams.status!='view'" :disabled="parentParams.status=='view'"
                               :style="{width:(item.width?item.width:100)+'%'}"/>
                    </FormItem>
                </Col>
            </Row>
        </Form>
        <Row>
            <Alert>
                <h2>分录信息</h2>
            </Alert>
            <Row class="operation">
                <Button @click="add" icon="md-add" type="primary" v-show="parentParams.status!='view'">新增</Button>
            </Row>
            <Table :columns="columns" :data="data" :loading="loading"
                   border ref="table">
                <template slot="action" slot-scope="{ row, index }">
                    <Button @click="edit(row,index)" size="small" style="margin-right:5px"
                            type="primary" v-show="parentParams.status!='view'">编辑
                    </Button>
                    <Button @click="view(row,index)" size="small" style="margin-right:5px"
                            type="primary">查看
                    </Button>
                    <Button @click="remove(row,index)" size="small" type="error"
                            v-show="parentParams.status!='view'">删除
                    </Button>
                </template>
                <template slot-scope="{ row, index }" slot="lendingDirection">
                    <span>{{setLendingDirection(row.lendingDirection)}}</span>
                </template>
            </Table>
        </Row>
        <Modal v-model="modalVisible" :title="modalTitle" :width="1000" :closable="false" :styles="styles"
               :mask-closable="false">
            <Form ref="voucherEntryFrom" :model="voucherEntryFrom" :label-width="100" :rules="voucherEntryValidate">
                <Row :gutter="32">
                    <Col  :xs="24" :sm="12" :md="12" :lg="10" :xl="12" :xxl="12">
                        <Form-item label="借贷方向" prop="lendingDirection" :required=true>
                            <Select placeholder="请选择" v-model="voucherEntryFrom.lendingDirection"
                                    :style="{width:(item.width?item.width:100)+'%'}"
                                    :disabled="this.entryStatus=='view'">
                                <Option :key="item.value" :value="item.value" v-for="item in lendingDirections">{{
                                    item.title }}
                                </Option>
                            </Select>
                        </Form-item>
                    </Col>
                    <Col :xs="24" :sm="12" :md="12" :lg="10" :xl="12" :xxl="12">
                        <FormItem label="排序号" prop="orderNum">
                            <InputNumber :min="1" v-model="voucherEntryFrom.orderNum"
                                         :precision="0"
                                         :style="{width:(item.width?item.width:50)+'%'}"
                                         :disabled="this.entryStatus=='view'"
                            ></InputNumber>
                        </FormItem>
                    </Col>
                </Row>
                <Row :gutter="32">
                    <Col :xs="12" :sm="12" :md="12" :lg="10" :xl="12" :xxl="12">
                        <FormItem label="科目代码" prop="subjectCode" :required=true>
                            <Input v-model="voucherEntryFrom.subjectCode"
                                   :style="{width:(item.width?item.width:100)+'%'}"
                                   :disabled="this.entryStatus=='view'"/>
                        </FormItem>
                    </Col>
                    <Col :xs="12" :sm="12" :md="12" :lg="10" :xl="12" :xxl="12">
                        <FormItem label="科目名称" prop="subjectName">
                            <Input v-model="voucherEntryFrom.subjectName" :required=true
                                   :style="{width:(item.width?item.width:100)+'%'}"
                                   :disabled="this.entryStatus=='view'"/>
                        </FormItem>
                    </Col>
                </Row>
                <Row :gutter="32">
                    <Col :xs="{ span: 22, offset: 1 }">
                        <Tag color="#19be6b" size="default">表达式展示语言</Tag>
                        <i-switch size="large" v-model="chineseLang">
                            <span slot="open">中文</span>
                            <span slot="close">程序</span>
                        </i-switch>
                    </Col>
                </Row>
                <Row :gutter="32" v-show="chineseLang">
                    <Col  :xs="22" :sm="22" :md="22" :lg="22" :xl="22" :xxl="22">
                        <FormItem label="金额表达式" prop="amountExpression" :required=false>
                            <Input v-model="voucherEntryFrom.chineseLang"
                                   :style="{width:(item.width?item.width:100)+'%'}" :disabled="this.entryStatus=='view'"
                                   autocomplete="off" :readonly="true"/>
                        </FormItem>
                    </Col>
                    <Col  :xs="2" :sm="2" :md="2" :lg="2" :xl="2" :xxl="2">
                        <Button @click="voucherConfig" size="small" type="warning" :disabled="this.entryStatus=='view'">
                            金额配置
                        </Button>
                    </Col>
                </Row>
                <Row :gutter="32" v-show="!chineseLang">
                    <Col  :xs="22" :sm="22" :md="22" :lg="22" :xl="22" :xxl="22">
                        <FormItem label="金额表达式" prop="amountExpression" :required=false>
                            <Input v-model="voucherEntryFrom.programLang"
                                   :style="{width:(item.width?item.width:100)+'%'}" :disabled="this.entryStatus=='view'"
                                   autocomplete="off" :readonly="true"/>
                        </FormItem>
                    </Col>
                    <Col :xs="2" :sm="2" :md="2" :lg="2" :xl="2" :xxl="2">
                        <Button @click="voucherConfig" size="small" type="warning" :disabled="this.entryStatus=='view'">
                            金额配置
                        </Button>
                    </Col>
                </Row>
                <Row :gutter="32">
                    <Col :span="24">
                        <FormItem label="辅助核算项目" prop="itemsList">
                            <Select v-model="voucherEntryFrom.itemsList" multiple
                                    :style="{width:(item.width?item.width:100)+'%'}"
                                    :disabled="this.entryStatus=='view'">
                                <Option v-for="item in itemsList" :value="item.value" :key="item.value">{{ item.title
                                    }}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <Row :gutter="32">
                    <Col :span="24">
                        <FormItem label="摘要" prop="explanation" :required=true>
                            <Input v-model="voucherEntryFrom.explanation"
                                   :style="{width:(item.width?item.width:100)+'%'}" :disabled="this.entryStatus=='view'"
                                   type="textarea" autocomplete="off"/>
                        </FormItem>
                    </Col>
                </Row>
            </Form>
            <div slot="footer">
                <Button @click="cancel" icon="md-backspace" :loading="submitLoading">返回</Button>
                <Button type="primary" :loading="submitLoading" @click="okClick" v-show="this.entryStatus!='view'">确定
                </Button>
            </div>
        </Modal>
        <Modal
            v-model="isShowVoucherConfig"
            :title="voucherConfigTitle"
            :width="1000"
            :closable="false"
            :mask-closable="false">
            <rule-tree v-if="dataLoad" :rule-data="ruleData" :ruleAtoms="ruleAtoms" :ruleName="ruleName"
                       :ruleGroup="ruleGroup" :businessScenario="businessScenario" @saved="returnRuleId"
                       :rule-id="ruleId" :entry-id="entryId"/>
            <div slot="footer">
                <Button size="small" @click="isShowVoucherConfig = false,dataLoad = false">取消</Button>
            </div>
            <Spin size="large" fix v-if="spinShow"></Spin>
        </Modal>
    </Card>
</template>
<script>
    import {deepClone} from "@/libs/utils/ObjectClone";
    import {getByTypes} from "_p/basic/api/admin/datadic";
    import ruiRules from '../voucher-rules/index';
    import {getVoucherInfo, save} from "@/projects/basic/api/contract/voucher/voucherTemplate";
    import {loadRuleDataById} from "@/projects/basic/api/contract/voucher/rule";
    import {queryAtomsByBizType} from "@/projects/basic/api/contract/voucher/voucherAtom"
    import {queryBusinessList} from "@/projects/basic/api/contract/voucher/voucherBusiness";
    import {
        deleteVoucherEntry,
        editVoucherEntry,
        getAllVoucherEntry,
        saveVoucherEntry,
    } from "@/projects/basic/api/contract/voucher/voucherEntry";

    export default {
        name: "voucher-basics-info",
        components: {
            ruleTree: ruiRules
        },
        props: {
            parentParams: {
                Object,
            },
        },
        data() {
            const validateChina = (rule, value, callback) => {
                let reg = /^[\u4e00-\u9fa5]+$/;
                if (!reg.test(value)) {
                    callback(new Error("只能输入中文"));
                } else {
                    callback();
                }
            };
            const validateNumber = (rule, value, callback) => {
                let reg = /^[0-9]*$/;
                if (!reg.test(value)) {
                    callback(new Error("只能输入数字"));
                } else {
                    callback();
                }
            };
            return {
                styles: {
                    height: 'calc(100% - 55px)',
                    overflow: 'auto',
                    paddingBottom: '53px',
                    position: 'static'
                },
                chineseLang: false,
                loading: false,
                isreadonly: false,
                submitLoading: false,
                saveLoading: false,
                spinShow: true,
                modalTitle: "",
                modalVisible: false,
                modalType: null,
                item: {
                    with: 200,
                },
                data: [],
                dataSources: [],
                itemsList: [],
                path: "contractAccount",
                voucherInfoFrom: {},
                voucherEntryFrom: {
                    lendingDirection: null,
                    orderNum: null,
                    subjectCode: null,
                    subjectName: null,
                    chineseLang: null,
                    programLang: null,
                    itemsList: null,
                    explanation: null,
                    ruleId: null
                },
                voucherInfoValidate: {
                    mainBusinessCode: [
                        {required: true, message: "主业务事件代码不能为空", trigger: "change"},
                    ],
                    mainBusiness: [
                        {required: true, message: "主业务事件不能为空", trigger: "change"},
                    ],
                    childBusiness: [
                        {required: true, message: "子业务事件不能为空", trigger: "change"},
                    ],
                    childBusinessCode: [
                        {required: true, message: "子业务事件代码不能为空", trigger: "change"},
                    ],
                    dataSources: [
                        {required: true, message: "数据来源不能为空", trigger: "change"},
                    ],
                    atomScope: [
                        {required: true, message: "适用场景不能为空", trigger: "change"},
                    ],
                    description: [
                        {required: true, message: "描述不能为空", trigger: "change"},
                    ]
                },
                voucherEntryValidate: {
                    lendingDirection: [
                        {required: true, message: "借贷方向不能为空", trigger: "change"},
                    ],
                    orderNum: [
                        {required: true, message: "排序号不能为空", type: "number", trigger: "change"},
                    ],
                    subjectCode: [
                        {required: true, message: "科目代码不能为空", trigger: "change"},
                        {validator: validateNumber, trigger: "change"},
                    ],
                    subjectName: [
                        {required: true, message: "科目名称不能为空", trigger: "change"},
                        // {validator: validateChina, trigger: "change"}
                    ],
                    explanation: [
                        {required: true, message: "摘要不能为空", trigger: "change"},
                    ]
                },
                columns: [
                    {
                        title: "操作",
                        key: "action",
                        align: "center",
                        slot: "action",
                        width: 200,
                        fixed: "left"
                    },
                    {
                        title: "排序号",
                        key: "orderNum",
                        align: "center"
                    },
                    {
                        title: "借贷方向",
                        key: "lendingDirection",
                        align: "center",
                        slot: "lendingDirection"
                    },
                    {
                        title: "科目代码",
                        key: "subjectCode",
                        align: "center"
                    },
                    {
                        title: "科目名称",
                        key: "subjectName",
                        render: (h, params) => {
                            return h('div', this.getSpan(h, params.row.subjectName));
                        },
                        align: "center"
                    },
                    {
                        title: "金额表达式",
                        key: "chineseLang",
                        render: (h, params) => {
                            return h('div', this.getSpan(h, params.row.chineseLang));
                        },
                        align: "center"
                    },
                    {
                        title: "辅助核算项目",
                        key: "itemsList",
                        render: (h, params) => {
                            let title = this.setItemsList(params.row.itemsList);
                            return h('div', this.getSpan(h, title));
                        },
                        align: "center"
                    },
                    {
                        title: "摘要",
                        key: "explanation",
                        render: (h, params) => {
                            return h('div', this.getSpan(h, params.row.explanation));
                        },
                        align: "center"
                    }
                ],
                lendingDirections: [],
                voucherAtomScope: [],
                isShowVoucherConfig: false,
                voucherConfigTitle: null,
                dataLoad: false,
                ruleAtoms: [],
                ruleData: [],
                ruleConfigTitle: null,
                ruleName: '凭证金额计算配置',
                ruleGroup: 'voucherRule',
                businessScenario: 'businessScenario',
                ruleId: null,
                entryId: null,
                entryStatus: null,
                fitScope: null,
                list1: [],
                visibleChild: false,
                visible: false,
                options1: [],
                list2: [],
                options2: [],
                scollshow: false,
                selectFrom:
                    {
                        condition: {
                            businessType: null,
                            businessCode: null,
                        }, pageNumber: 1, pageSize: 10
                    },
                searchMainKey: "",
                searchChildKey: "",
            }
        },
        mounted() {
            let {status, id, childBusinessCode} = this.parentParams;
            if ('new' == status) {
                this.isreadonly = true;
            } else {
                this.voucherInfoFrom.id = id;
                this.getVoucherInfo();
            }
            this.loadForm();
            this.initDatadic();

        },
        methods: {
            //加载页面数据
            loadForm() {
                this.remoteMethodChild();
                this.remoteMethodMain();
            },
            initDatadic() {
                //数据字典
                let arr = ["dataSources", "auxiliaryAccountingItems", "lendingDirection", "voucherAtomScope"];
                getByTypes(arr).then(res => {
                    if (res.code === "0000") {
                        this.dataSources.push(...res.data.dataSources);
                        this.itemsList.push(...res.data.auxiliaryAccountingItems);
                        this.lendingDirections.push(...res.data.lendingDirection);
                        this.voucherAtomScope.push(...res.data.voucherAtomScope);
                    }
                });
            },
            getVoucherInfo() {
                getVoucherInfo(this.voucherInfoFrom.id).then(res => {
                    if (res.code === "0000") {
                        this.voucherInfoFrom = res.data.voucherInfo;
                        this.fitScope = this.voucherInfoFrom.atomScope;
                        this.data = res.data.entryList;
                    }
                });
            },
            getSpan(h, val) {
                return [
                    h('span', {
                        style: {
                            display: 'inline-block',
                            width: '100%',
                            overflow: 'hidden',
                            textOverflow: 'ellipsis',
                            whiteSpace: 'nowrap'
                        },
                        domProps: {title: val},
                        on: {
                            click: (e) => {
                                e.stopPropagation();
                            }
                        }
                    }, val)
                ];
            },
            setLendingDirection(val) {
                let dic = {};
                this.lendingDirections.forEach(column => {
                    if (column.value === val) {
                        dic = column;
                    }
                });
                return dic = {} ? dic.title : val;
            },
            setItemsList(value) {
                if (!value || value == '' || value.length == 0) {
                    return '';
                }
                if (this.itemsList && this.itemsList.length > 0) {
                    let rtn = [];
                    this.itemsList.forEach(dic => {
                        if (value.includes(dic.value)) {
                            rtn.push(dic.title);
                        }
                    })
                    return rtn.join(',');
                } else {
                    return value.join(',')
                }
            },
            save() {
                let self = this;
                self.$refs.voucherInfoFrom.validate(validate => {
                    if (validate) {
                        this.saveLoading = true;
                        save(this.voucherInfoFrom).then(res => {
                            this.saveLoading = false;
                            if (res.code === "0000") {
                                this.voucherInfoFrom = res.data;
                                this.fitScope = this.voucherInfoFrom.atomScope;
                                this.parentParams.status = "edit";
                            }
                            this.$Message.success("保存成功");
                        }).catch(() => {
                            this.saveLoading = false;
                        });
                    } else {
                        self.$Message.error("数据错误");
                    }
                })
            },
            add() {
                this.modalTitle = "新增凭证分录信息";
                this.modalType = '0';
                this.entryStatus = 'new';
                if ('new' == this.parentParams.status) {
                    this.$Message.success("请先保存凭证信息！");
                    return;
                }
                let self = this;
                self.voucherEntryFrom = {
                    lendingDirection: null,
                    orderNum: null,
                    subjectCode: null,
                    subjectName: null,
                    chineseLang: null,
                    programLang: null,
                    itemsList: null,
                    explanation: null,
                    ruleId: null
                };
                this.$nextTick(() => {
                    self.$refs.voucherEntryFrom.resetFields();
                    this.modalVisible = true;
                    self.voucherEntryFrom.correlationId = this.voucherInfoFrom.id;
                    self.voucherEntryFrom.orderNum = 1;
                    this.data.forEach(voucherEntry => {
                            if (voucherEntry.orderNum + 1 > self.voucherEntryFrom.orderNum) {
                                self.voucherEntryFrom.orderNum = voucherEntry.orderNum + 1
                            }
                        }
                    )
                })
            },
            //查询主事件代码
            remoteMethodMain() {
                queryBusinessList({businessType: "main"}, "contractAccount")
                    .then(res => {
                        if (res.code === "0000") {
                            this.list1 = res.data;
                            this.options1 = this.list1;
                        }
                    }).catch(() => {
                    this.list1 = [];
                    this.options1 = this.list1;
                });
            },
            //查询主事件代码
            handleReachMainBottom() {
                return new Promise(resolve => {
                    setTimeout(() => {
                        const last = this.options1[this.options1.length - 1];
                        for (let i = 1; i < 11; i++) {
                            this.options1.push(last + i);
                        }
                        resolve();
                    }, 2000);
                });
            },
            //加载主事件
            remoteMain() {
                this.options1 = [];
                for (var i = 0; i < this.list1.length; i++) {
                    if (this.list1[i].businessCode.indexOf(this.searchMainKey) > -1) {
                        this.options1.push(this.list1[i])
                    }
                }
            },
            // 主事件赋值
            scollListClick(val) {
                this.options1.forEach(c => {
                    if (c.businessCode == val) {
                        this.voucherInfoFrom.mainBusinessCode = c.businessCode;
                        this.voucherInfoFrom.mainBusiness = c.business;
                        this.voucherInfoFrom.childBusinessCode = "";
                        this.voucherInfoFrom.childBusiness = "";
                        this.visible = false;
                    }
                })
                this.options2 = [];
                for (var i = 0; i < this.list2.length; i++) {
                    if (this.list2[i].mainBusinessCode == this.voucherInfoFrom.mainBusinessCode) {
                        this.options2.push(this.list2[i])
                    }
                }
            },
            //  子事件赋值
            scollListChldClick(val) {
                this.options2.forEach(c => {
                    if (c.businessCode == val) {
                        this.voucherInfoFrom.childBusinessCode = c.businessCode;
                        this.voucherInfoFrom.childBusiness = c.business;
                        this.visibleChild = false;
                    }
                })
            },
            //查询子事件代码
            remoteMethodChild() {
                queryBusinessList({businessType: "child"}, "contractAccount")
                    .then(res => {
                        if (res.code === "0000") {
                            this.list2 = res.data;
                            this.options2 = this.list2;
                        }
                    }).catch(() => {
                    this.list2 = [];
                    this.options2 = this.list2;
                });
            },
            //查询子事件代码
            handleReachChildBottom() {
                return new Promise(resolve => {
                    setTimeout(() => {
                        const last = this.options2[this.options2.length - 1];
                        for (let i = 1; i < 11; i++) {
                            this.options2.push(last + i);
                        }
                        resolve();
                    }, 2000);
                });
            },
            //加载子事件
            remoteChild() {
                this.options2 = [];
                for (var i = 0; i < this.list2.length; i++) {
                    if (this.list2[i].businessCode.indexOf(this.searchChildKey) > -1 && this.list2[i].mainBusinessCode == this.voucherInfoFrom.mainBusinessCode) {
                        this.options2.push(this.list2[i])
                    }
                }
            },
            cancel() {
                this.modalTitle = "";
                this.modalVisible = false;
                this.submitLoading = false;
                this.getAllVoucherEntry();
            },
            okClick() {
                this.$refs.voucherEntryFrom.validate(valid => {
                    if (valid) {
                        if (this.modalType === '0') {
                            this.submitLoading = true;
                            saveVoucherEntry(this.voucherEntryFrom)
                                .then(res => {
                                    this.submitLoading = false;
                                    if (res.code === "0000") {
                                        this.voucherEntryFrom = res.data;
                                        this.entryId = this.voucherEntryFrom.id;
                                        this.entryStatus = 'edit';
                                        this.modalType = '1';
                                        this.$Message.success("操作成功");
                                    }
                                }).catch(() => {
                                this.submitLoading = false;
                            });
                        } else {
                            // 编辑
                            this.submitLoading = true;
                            editVoucherEntry(this.voucherEntryFrom)
                                .then(res => {
                                    this.submitLoading = false;
                                    if (res.code === "0000") {
                                        this.$Message.success("操作成功");
                                    }
                                }).catch(() => {
                                this.submitLoading = false;
                            });

                        }
                    }
                });
            },
            getAllVoucherEntry() {
                this.loading = true;
                getAllVoucherEntry(this.voucherInfoFrom.id).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.data = res.data;
                    }
                }).catch(() => {
                    this.loading = false;
                });
            },
            remove(row, index) {
                let self = this;
                self.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除?",
                    onOk: () => {
                        this.loading = true;
                        deleteVoucherEntry(row.id).then(res => {
                            this.loading = false;
                            if (res.code === "0000") {
                                this.$Message.success("删除成功");
                                this.getAllVoucherEntry();
                            }
                        }).catch(() => {
                            this.loading = false;
                        });
                    }
                });
            },
            edit(row, index) {
                this.modalTitle = '编辑凭证分录信息';
                this.modalType = '1';
                this.entryStatus = 'edit';
                this.modalVisible = true;
                this.$nextTick(() => {
                    this.voucherEntryFrom = deepClone(row);
                    this.entryId = this.voucherEntryFrom.id;
                })
            },
            view(row, index) {
                this.modalTitle = '凭证分录信息';
                this.voucherEntryFrom = deepClone(row);
                this.entryId = this.voucherEntryFrom.id;
                this.modalVisible = true;
                this.entryStatus = "view";
            },
            backPage() {
                this.$emit('backPage', "退回");
            },
            voucherConfig() {
                if (this.voucherEntryFrom.id == null) {
                    this.$Message.warning("请先保存凭证分录信息！");
                    return;
                }
                if (this.voucherEntryFrom.id != null) {
                    this.ruleData = [];
                    this.ruleId = this.voucherEntryFrom.id;
                    this.queryAtomsByBizType();
                    loadRuleDataById(this.ruleId, this.path).then(res => {
                        if (res.code = '0000') {
                            this.spinShow = false;
                            if (res.data.length > 0) {
                                this.ruleData = res.data;
                            }
                            this.dataLoad = true;
                            this.isShowVoucherConfig = true;
                        }
                    });
                } else {
                    this.ruleId = null;

                    this.dataLoad = true;
                    this.isShowVoucherConfig = true;
                }
                this.ruleConfigTitle = "编辑规则";
                this.businessScenario = this.voucherEntryFrom.correlationId;
            },
            returnRuleId(ruleId, chineseLang, programLang) {
                this.ruleId = ruleId;
                console.log(ruleId);
                this.dataLoad = false;
                this.isShowVoucherConfig = false;
                // 编辑
                this.voucherEntryFrom.chineseLang = chineseLang;
                this.voucherEntryFrom.programLang = programLang;
            },
            queryAtomsByBizType() {
                queryAtomsByBizType(this.fitScope, this.path).then(res => {
                    if (res.code === "0000") {
                        this.ruleAtoms = res.data;
                    }
                });
            },
        }
    }
</script>
